/*
 *  $Id: RagimaTheFire.cs 1055 2010-05-19 12:02:44Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

namespace Ragima.Cards001.Fire.Creatures {
    public class RagimaTheFire: RagimaCreatureCard {
        public RagimaTheFire() : base("001_f_c_r_the_fire", ElementType.Fire) {
            Level = CompleteLevel.ReadyForTest;
            Value = 100;
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.FlightBlock>();
            affects.Add(new Affects.MultiBlock(3));
            affects.Add<RagimaTheFireAffect>();
        }

        private class RagimaTheFireAffect: Affect {
            public override string Id {
                get { return AffectManager.GetCardId<RagimaTheFire>(null); }
            }

            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.AddVanguard(Affects.Vanguard.Always);
                LocalSummary.OnDefenceReady += DoDefence;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.RemoveVanguard(Affects.Vanguard.Always);
                LocalSummary.OnDefenceReady -= DoDefence;
            }

            private void DoDefence(Creature creature) {
                List<Creature> attackers = new List<Creature>();
                foreach (Creature attacker in creature.Owner.Enemy.GetCreatures())
                    if (attacker.Defenders.Contains(creature))
                        attackers.Add(attacker);
                if (attackers.Count == 0) return;
                int power = Math.Max(5 - attackers.Count, 1);
                foreach (Creature attacker in attackers)
                    attacker.AddAffect(new Affects.Scorch(power));
            }
        }
    }
}
